package org.springboot.szsrcb.srvice;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springboot.szsrcb.controller.ReqRestController_work_log;
import org.springboot.szsrcb.entity.Req_base_info;
import org.springboot.szsrcb.entity.Req_bill;
import org.springboot.szsrcb.entity.Req_team_info_log;
import org.springboot.szsrcb.entity.Req_work_log;
import org.springboot.szsrcb.entity.Req_workload_info;
import org.springboot.szsrcb.entity.Test_base_info;
import org.springboot.szsrcb.entity.Test_bill;
import org.springboot.szsrcb.entity.Test_team_info_log;
import org.springboot.szsrcb.entity.Test_testing_info;
import org.springboot.szsrcb.entity.Test_work_log;
import org.springboot.szsrcb.entity.Test_workload_info;
import org.springboot.szsrcb.entity.User;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_base_infoRowMapper;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_billRowMapper;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_team_info_log_RowMapper;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_work_logRowMapper;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_workload_infoRowMapper;
import org.springboot.szsrcb.srvice.Req_bill_Service.Req_workload_info_RowMapper;
import org.springboot.szsrcb.srvice.UserService.UserRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

@Service
public class Test_bill_Service {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	private Att_Service att_Service;

	private static final Logger logger = LoggerFactory.getLogger(ReqRestController_work_log.class);

	private boolean update_test_project_node_time(Integer test_id, String node_value,int is_insert) {
		String value1="1领取需求";
		String value2="2提交需求";
		String value3="3开始开发";
		String value4="4系统测试";
		String value5="5应用测试";
		String value6="6完成测试";
		String value7="7完成上线";
		String value8="8结束跟踪";
		List rows = jdbcTemplate.queryForList("SELECT id FROM test_node_info where test_id="+test_id);
		if(rows.size()>0){
			is_insert=0;
		}else{
			is_insert=1;
		}
		if(is_insert==1){
			String sql ="";
			if(node_value.equals(value1)){
				sql = "INSERT INTO test_node_info(test_id,receive_req) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value2)){
				sql = "INSERT INTO test_node_info(test_id,submit_req) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value3)){
				sql = "INSERT INTO test_node_info(test_id,start_dev) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value4)){
				sql = "INSERT INTO test_node_info(test_id,system_test) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value5)){
				sql = "INSERT INTO test_node_info(test_id,application_testing) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value6)){
				sql = "INSERT INTO test_node_info(test_id,test_finish) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value7)){
				sql = "INSERT INTO test_node_info(test_id,online_finish) VALUES (" + test_id+",now())";
			}
			if(node_value.equals(value8)){
				sql = "INSERT INTO test_node_info(test_id,trace_finish) VALUES (" + test_id+",now())";
			}
			logger.info("sql :" + sql);
			int r = jdbcTemplate.update(sql);
			if(r==1){
				return true;
			}else{
				return false;
			}
		}else{
			String sql ="";
			if(node_value.equals(value1)){
				sql = "UPDATE test_node_info SET receive_req=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value2)){
				sql = "UPDATE test_node_info SET submit_req=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value3)){
				sql = "UPDATE test_node_info SET start_dev=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value4)){
				sql = "UPDATE test_node_info SET system_test=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value5)){
				sql = "UPDATE test_node_info SET application_testing=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value6)){
				sql = "UPDATE test_node_info SET test_finish=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value7)){
				sql = "UPDATE test_node_info SET online_finish=now() WHERE test_id=" + test_id;
			}
			if(node_value.equals(value8)){
				sql = "UPDATE test_node_info SET trace_finish=now() WHERE test_id=" + test_id;
			}
			
			logger.info("sql :" + sql);
			int r = jdbcTemplate.update(sql);
			if(r==1){
				return true;
			}else{
				return false;
			}
		}
		
		
	}
	public boolean save_test_bill(Test_bill test_bill,String user_name) {

		String sql = "INSERT INTO test_bill"
				+ "(req_id,test_report_status,test_complete_date,test_guide,req_remark,create_date,test_status,test_technical_director,creator)values(?,?,?,?,?,?,?,?,?);";
		try {
			PreparedStatementSetter pss = new PreparedStatementSetter() {

				@Override
				public void setValues(PreparedStatement ps) throws SQLException {
					ps.setInt(1, test_bill.getReq_id());
					ps.setString(2, test_bill.getTest_report_status());
					ps.setDate(3, new java.sql.Date(test_bill.getTest_complete_date().getTime()));
					ps.setString(4, test_bill.getTest_guide());
					ps.setString(5, test_bill.getReq_remark());
					Date date = new java.sql.Date(new java.util.Date().getTime());
					Timestamp timeStamp = new Timestamp(date.getTime());
					ps.setTimestamp(6, timeStamp);
					ps.setString(7, "已接收");
					ps.setString(8, test_bill.getTest_technical_director());
					ps.setString(9, user_name);
				}
			};
			Integer get_r = jdbcTemplate.update(sql, pss);
			if(get_r==1){
				Test_bill test_bill_new=search_a_test_bill(String.valueOf(test_bill.getReq_id()));
				update_test_project_node_time(test_bill_new.getId(),"5应用测试",1);
			}
			
			if (get_r == 1) {
				String sql_u = "Update req_bill Set is_include_test_project ='是' WHERE id = " + test_bill.getReq_id() + ";";
				
				int u_r = jdbcTemplate.update(sql_u);
				
				logger.info("result "+u_r+" sql_u :" + sql_u);
				String sql2 = "Select * FROM test_bill WHERE req_id = " + test_bill.getReq_id() + ";";
				logger.info("sql2 :" + sql2);
				List<Test_bill> l_q = jdbcTemplate.query(sql2, new Test_billRowMapper());
				Test_bill r = l_q.get(0);
				r.setAtt_id(test_bill.getAtt_id());
				logger.info("r id :" + r.getId() + " " + r.getReq_id());
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("relation_test_id", r.getId().toString());
				map.put("att_ids", r.getAtt_id());
				if (r.getAtt_id().equals("")) {
					return true;
				} else {
					return att_Service.new_test_update_att(map);
				}

			} else {
				return false;
			}

		} catch (Exception e) {

			logger.info("Exception e :" + e.getMessage());
			return false;
		}
	}

	class Test_billRowMapper implements RowMapper<Test_bill> {
		@Override
		public Test_bill mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_bill test = new Test_bill();
			test.setId(rs.getInt("ID"));
			test.setReq_id(rs.getInt("req_id"));
			test.setTest_report_status(rs.getString("test_report_status"));
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String d_str = "";
			if (rs.getDate("test_complete_date") != null) {
				d_str = sdf.format(rs.getDate("test_complete_date"));
			}
			test.setTest_complete_date(d_str);

			test.setTest_guide(rs.getString("test_guide"));
			test.setReq_remark(rs.getString("req_remark"));
			test.setCreate_date(rs.getTimestamp("create_date"));
			test.setCreator(rs.getString("creator"));
			test.setTest_technical_director(rs.getString("test_technical_director"));
			test.setTest_status(rs.getString("test_status"));
			test.setSelect_reason(rs.getString("select_reason"));
			test.setOther_reason(rs.getString("other_reason"));
			return test;
		}

	}

	public Test_bill search_a_test_bill(String g_req_id) {
		String sql = "SELECT * FROM test_bill WHERE req_id=" + g_req_id;
		logger.info("从数据库执行" + sql);
		List<Test_bill> l_u = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_u.size() > 0) {
			return l_u.get(0);
		} else {
			return null;
		}

	}

	public Test_bill search_a_test_bill_by_id(String test_id) {
		String sql = "SELECT * FROM test_bill WHERE id=" + test_id;
		logger.info("从数据库执行" + sql);
		List<Test_bill> l_u = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_u.size() > 0) {
			return l_u.get(0);
		} else {
			return null;
		}

	}

	public boolean save_test_base_info(Test_base_info test_base_info) {
		String sql = "INSERT INTO test_base_info"
				+ "(test_id,test_head,test_executor,test_difficult,test_workload,"
				+ "test_plan_date,test_introduction,test_remark,create_time)" + "values(?,?,?,?,?,?,?,?,?);";
		logger.info("从数据库执行" + sql);
		try {
			PreparedStatementSetter pss = new PreparedStatementSetter() {

				@Override
				public void setValues(PreparedStatement ps) throws SQLException {
					ps.setInt(1, test_base_info.getTest_id());
					ps.setString(2, test_base_info.getTest_head());
					ps.setString(3, test_base_info.getTest_executor());
					ps.setString(4, test_base_info.getTest_difficult());
					ps.setFloat(5, test_base_info.getTest_workload());
					//ps.setFloat(6, test_base_info.getTest_actual_workload());
					ps.setDate(6, new java.sql.Date(test_base_info.getTest_plan_date().getTime()));
					ps.setString(7, test_base_info.getTest_introduction());
					ps.setString(8, test_base_info.getTest_remark());
					Date date = new java.sql.Date(new java.util.Date().getTime());
					Timestamp timeStamp = new Timestamp(date.getTime());
					ps.setTimestamp(9, timeStamp);
				}
			};
			Integer get_r = jdbcTemplate.update(sql, pss);
			if (get_r == 1) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("relation_test_id", test_base_info.getTest_id());
				map.put("att_ids", test_base_info.getAtt_id());
				boolean get_r2 = false;
				if (test_base_info.getAtt_id().equals("")) {
					get_r2 = true;
				} else {
					get_r2 = att_Service.test_update_att(map);
				}
				if (get_r2) {
					/*String set_str="";
					if(test_base_info.getTest_introduction()!=null){
						set_str=", test_guide='"+test_base_info.getTest_introduction()+"' ";
					}
					if(test_base_info.getTest_remark()!=null){
						set_str=set_str+", req_remark='"+test_base_info.getTest_remark()+"' ";
					}*/
					String sql2 = "UPDATE test_bill  SET  test_status= '已分配' , test_guide=? , req_remark=? WHERE id=?" ;
					logger.info("从数据库执行" + sql2);
					PreparedStatementSetter pss2 = new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps) throws SQLException {
							
							
							if(test_base_info.getTest_introduction()!=null){
								ps.setString(1, test_base_info.getTest_introduction());
							}else{
								ps.setString(1, "");
							}
							
							
							
							if(test_base_info.getTest_remark()!=null){
								ps.setString(2, test_base_info.getTest_remark());
							}else{
								ps.setString(2, "");
							}
							
							ps.setInt(3, test_base_info.getTest_id());
						}
					};
					Integer get_r3 = jdbcTemplate.update(sql2,pss2);
					if (get_r3 > 0) {
						return true;
					} else {
						return false;
					}
				} else {
					return false;
				}

			} else {
				return false;
			}
		} catch (Exception e) {
			logger.info("Exception e :" + e.getMessage());
			return false;
		}

	}

	public List<Test_bill> search_test_bill_list(String params) {
		String[] str_array = params.split(",", 6);
		String g_req_title = str_array[0];
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sf = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss z", Locale.ENGLISH);
		// Date d = sf.parse(s);

		String g_start = null;
		String g_end = null;

		try {
			g_start = sdf.format(sf.parse(str_array[1]));
			g_end = sdf.format(sf.parse(str_array[2]));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String g_req_bill_no = str_array[3];
		String g_test_technical_director = str_array[4];
		String g_test_status = str_array[5];

		String sql = "select test_bill.* from test_bill,req_bill where test_bill.req_id =req_bill.id ";
		if (!g_req_title.equals("")) {
			sql = sql + " AND req_bill.req_title like '%" + g_req_title + "%'";
		}

		sql = sql + " AND (test_bill.create_date between '" + g_start + "'";
		sql = sql + " AND '" + g_end + " 23:59:59')";

		if (!g_req_bill_no.equals("")) {
			sql = sql + " AND req_bill.req_bill_no like '%" + g_req_bill_no + "%'";
		}
		if (!g_test_technical_director.equals("")) {
			sql = sql + " AND test_bill.test_technical_director like '%" + g_test_technical_director + "%'";
		}
		if (!g_test_status.equals("")) {
			sql = sql + " AND test_bill.test_status like '%" + g_test_status + "%'";
		}
		/*
		 * if (map.size() == 0) { sql = sql + " req_status in ('已接收')"; } else {
		 * sql = sql + "AND req_status in ('已接收')"; }
		 */
		sql=sql+" order by  test_bill.id desc";

		logger.info("从数据库执行" + sql);
		List<Test_bill> l_q = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}

	}
	
	@SuppressWarnings("null")
	public List<Test_bill> search_test_bill_list_my(String params,String user_name) {
		String[] str_array = params.split(",", 6);
		String g_req_title = str_array[0];
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sf = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss z", Locale.ENGLISH);
		// Date d = sf.parse(s);

		String g_start = null;
		String g_end = null;

		try {
			g_start = sdf.format(sf.parse(str_array[1]));
			g_end = sdf.format(sf.parse(str_array[2]));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String g_req_bill_no = str_array[3];
		String g_test_technical_director = str_array[4];
		String g_test_status = str_array[5];

		String sql = "select test_bill.* from test_bill,req_bill where test_bill.req_id =req_bill.id ";
		if (!g_req_title.equals("")) {
			sql = sql + " AND req_bill.req_title like '%" + g_req_title + "%'";
		}

		sql = sql + " AND (test_bill.create_date between '" + g_start + "'";
		sql = sql + " AND '" + g_end + " 23:59:59')";

		if (!g_req_bill_no.equals("")) {
			sql = sql + " AND req_bill.req_bill_no like '%" + g_req_bill_no + "%'";
		}
		if (!g_test_technical_director.equals("")) {
			sql = sql + " AND test_bill.test_technical_director like '%" + g_test_technical_director + "%'";
		}
		if (!g_test_status.equals("")) {
			sql = sql + " AND test_bill.test_status like '%" + g_test_status + "%'";
		}
		/*
		 * if (map.size() == 0) { sql = sql + " req_status in ('已接收')"; } else {
		 * sql = sql + "AND req_status in ('已接收')"; }
		 */
		sql=sql+" ORDER BY test_bill.id DESC ";
		logger.info("从数据库执行" + sql);
		List<Test_bill> l_q = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_q.size() > 0) {
			List<Test_bill> r_list=new ArrayList<Test_bill>();
			for (Test_bill test_bill : l_q) {
				Test_base_info test_base_info= this.search_a_test_base_info_by_testid(String.valueOf(test_bill.getId()));
				if (test_base_info != null) {
					String g_Test_head =test_base_info.getTest_head();
					if (g_Test_head != null) {
						if(g_Test_head.contains(user_name)){
							r_list.add(test_bill);
						}else{
							String g_Test_executor =test_base_info.getTest_executor();
							if(g_Test_executor.contains(user_name)){
								r_list.add(test_bill);
							}
						}
					}
					
				}				
			}
			return r_list;
		} else {
			return null;
		}

	}

	public boolean check_is_test_head(String name, String test_id) {
		String sql = "SELECT * FROM test_base_info WHERE test_id=" + test_id + " AND test_head like '" + name + "'";
		logger.info("从数据库执行" + sql);
		List<Test_base_info> l_u = jdbcTemplate.query(sql, new Test_base_infoRowMapper());
		if (l_u.size() > 0) {
			return true;
		} else {
			return false;
		}
	}

	public Test_base_info search_a_test_base_info_by_testid(String test_id) {
		String sql = "SELECT * FROM test_base_info WHERE test_id=" + test_id;
		logger.info("从数据库执行" + sql);
		List<Test_base_info> l_u = jdbcTemplate.query(sql, new Test_base_infoRowMapper());
		if (l_u.size() > 0) {
			return l_u.get(0);
		} else {
			return null;
		}
	}

	class Test_base_infoRowMapper implements RowMapper<Test_base_info> {
		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet,
		 * int)
		 */
		@Override
		public Test_base_info mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_base_info Test_base_info = new Test_base_info();
			Test_base_info.setId(rs.getInt("ID"));
			Test_base_info.setTest_head(rs.getString("test_head"));
			Test_base_info.setTest_executor(rs.getString("test_executor"));
			Test_base_info.setTest_difficult(rs.getString("test_difficult"));
			Test_base_info.setTest_workload(rs.getFloat("test_workload"));
			//Test_base_info.setTest_actual_workload(rs.getFloat("test_actual_workload"));
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String d_str = "";

			if (rs.getDate("test_plan_date") != null) {
				d_str = sdf.format(rs.getDate("test_plan_date"));
			}
			Test_base_info.setTest_plan_date(d_str);

			d_str = "";
			if (rs.getDate("actual_finish_date") != null) {
				d_str = sdf.format(rs.getDate("actual_finish_date"));
			}
			Test_base_info.setActual_finish_date(d_str);

			Test_base_info.setTest_introduction(rs.getString("test_introduction"));
			Test_base_info.setTest_remark(rs.getString("test_remark"));
			Test_base_info.setNode_value(rs.getString("node_value"));
			Test_base_info.setCreate_time(rs.getDate("create_time"));
			return Test_base_info;
		}

	}
	public boolean save_test_base_info_for_insert(Test_base_info test_base_info) {
		java.util.Date d = test_base_info.getTest_plan_date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String d_str = sdf.format(d);
		java.util.Date d2 = test_base_info.getActual_finish_date();
		String d_str2=null;
		if(d2!=null){
			d_str2= sdf.format(d2);
		}
		
		

		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String d_str3 = sdf2.format(new java.util.Date());
		/*String sql = "UPDATE test_base_info SET " + "test_difficult ='" + test_base_info.getTest_difficult() + "',"
				+ "test_workload =" + test_base_info.getTest_workload() + ","+ "test_plan_date=Date('" + d_str + "'),"
				+ " actual_finish_date=Date('" + d_str2 + "')," + "test_introduction='"
				+ test_base_info.getTest_introduction() + "'," + "test_remark='" + test_base_info.getTest_remark()
				+ "'," + " last_modify_time=Date('" + d_str3 + "')" + ", node_value='" + test_base_info.getNode_value()+"' " 
				+" WHERE test_id=" + test_base_info.getTest_id();

		logger.info("从数据库执行" + sql);*/
		
		
		
		String sql = "INSERT INTO test_base_info"
				+ "(test_id,test_difficult,test_workload,"
				+ "test_plan_date,actual_finish_date,test_introduction,test_remark,node_value,create_time) values(?,?,?,?,?,?,?,?,?)";
		logger.info("从数据库执行" + sql);
		
			PreparedStatementSetter pss = new PreparedStatementSetter() {

				@Override
				public void setValues(PreparedStatement ps) throws SQLException {
					ps.setInt(1, test_base_info.getTest_id());
					ps.setString(2, test_base_info.getTest_difficult());
					ps.setFloat(3, test_base_info.getTest_workload());

					ps.setDate(4, new java.sql.Date(d.getTime()));
					//ps.setFloat(6, test_base_info.getTest_actual_workload());
					if(d2==null){
						ps.setDate(5, null);
					}else{
						ps.setDate(5, new java.sql.Date(d2.getTime()));
					}
					
					ps.setString(6, test_base_info.getTest_introduction());
					ps.setString(7, test_base_info.getTest_remark());
					ps.setString(8, test_base_info.getNode_value());
					Date date = new java.sql.Date(new java.util.Date().getTime());
					Timestamp timeStamp = new Timestamp(date.getTime());
					ps.setTimestamp(9, timeStamp);
				}
			};
			
		Integer get_r = jdbcTemplate.update(sql,pss);
		if (get_r == 1) {
			update_test_project_node_time(test_base_info.getTest_id(), test_base_info.getNode_value(), test_base_info.getNode_value_date());
		}
		if (get_r == 1) {
			update_test_project_node_time( test_base_info.getTest_id(), test_base_info.getNode_value(),0);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("relation_test_id", test_base_info.getTest_id());
			map.put("att_ids", test_base_info.getAtt_id());
			boolean get_r2 = false;
			if (test_base_info.getAtt_id().equals("")) {
				get_r2 = true;
			} else {
				get_r2 = att_Service.test_update_att(map);
			}
			if (get_r2) {
				/*String set_str="";
				if(test_base_info.getTest_introduction()!=null){
					set_str=", test_guide='"+test_base_info.getTest_introduction()+"' ";
				}
				if(test_base_info.getTest_remark()!=null){
					set_str=set_str+", req_remark='"+test_base_info.getTest_remark()+"' ";
				}
				String sql2 = "UPDATE test_bill  SET  test_status= '" + test_base_info.getTest_status() + "' "+set_str+" WHERE id="
						+ test_base_info.getTest_id();*/
				String sql2 = "UPDATE test_bill  SET  test_status= '" + test_base_info.getTest_status() + "' , test_guide=? , req_remark=? WHERE id=?" ;
				logger.info("从数据库执行" + sql2);
				PreparedStatementSetter pss2 = new PreparedStatementSetter() {

					@Override
					public void setValues(PreparedStatement ps) throws SQLException {
						
						
						if(test_base_info.getTest_introduction()!=null){
							ps.setString(1, test_base_info.getTest_introduction());
						}else{
							ps.setString(1, "");
						}					
						
						if(test_base_info.getTest_remark()!=null){
							ps.setString(2, test_base_info.getTest_remark());
						}else{
							ps.setString(2, "");
						}
						
						ps.setInt(3, test_base_info.getTest_id());
					}
				};
				logger.info("从数据库执行" + sql2);
				Integer get_r3 = jdbcTemplate.update(sql2,pss2);
				if (get_r3 > 0) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}

		} else {
			return false;
			
		}
		
	}
	
	public boolean save_test_base_info_in_modify(Test_base_info test_base_info) {
		java.util.Date d = test_base_info.getTest_plan_date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String d_str = sdf.format(d);
		java.util.Date d2 = test_base_info.getActual_finish_date();
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String d_str3 = sdf2.format(new java.util.Date());
		
		String update_str="";
		if(d2!=null){
			String d_str2 = sdf.format(d2);
			update_str="UPDATE test_base_info SET " + "test_difficult ='" + test_base_info.getTest_difficult() + "',"
					+ "test_workload =" + test_base_info.getTest_workload() + ","+ "test_plan_date=Date('" + d_str + "'),"
					+ " actual_finish_date=Date('" + d_str2 + "')," 
					//+ "test_introduction='"
					//+ test_base_info.getTest_introduction() + "'," + "test_remark='" + test_base_info.getTest_remark()
					//+ "'," + " last_modify_time=Date('" + d_str3 + "')" + ", node_value='" + test_base_info.getNode_value()+"' " 
					//+ "',"
					+ " last_modify_time=Now()" + ", node_value='" + test_base_info.getNode_value()+"' "
					+" WHERE test_id=" + test_base_info.getTest_id();
		}else{
			update_str="UPDATE test_base_info SET " + "test_difficult ='" + test_base_info.getTest_difficult() + "',"
					+ "test_workload =" + test_base_info.getTest_workload() + ","+ "test_plan_date=Date('" + d_str + "'),"
					//+ " actual_finish_date=Date('" + d_str2 + "')," 
					//+ "test_introduction='"
					//+ test_base_info.getTest_introduction() + "'," + "test_remark='" + test_base_info.getTest_remark()
					//+ "'," + " last_modify_time=Date('" + d_str3 + "')" + ", node_value='" + test_base_info.getNode_value()+"' " 
					//+ "',"
					+ " last_modify_time=Now()" + ", node_value='" + test_base_info.getNode_value()+"' "
					+" WHERE test_id=" + test_base_info.getTest_id();
		}
		

		
		String sql = update_str;
		logger.info("从数据库执行" + sql);
		
		Integer get_r = jdbcTemplate.update(sql);
		if (get_r == 1) {
			java.util.Date getNode_value_date=test_base_info.getNode_value_date();
			if(getNode_value_date!=null){
				update_test_project_node_time(test_base_info.getTest_id(), test_base_info.getNode_value(), test_base_info.getNode_value_date());
			}	
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("relation_test_id", test_base_info.getTest_id());
			map.put("att_ids", test_base_info.getAtt_id());
			boolean get_r2 = false;
			if (test_base_info.getAtt_id().equals("")) {
				get_r2 = true;
			} else {
				get_r2 = att_Service.test_update_att(map);
			}
			if (get_r2) {
				/*String set_str="";
				if(test_base_info.getTest_introduction()!=null){
					set_str=", test_guide='"+test_base_info.getTest_introduction()+"' ";
				}
				if(test_base_info.getTest_remark()!=null){
					set_str=set_str+", req_remark='"+test_base_info.getTest_remark()+"' ";
				}
				String sql2 = "UPDATE test_bill  SET  test_status= '" + test_base_info.getTest_status() + "' "+set_str+" WHERE id="
						+ test_base_info.getTest_id();
				logger.info("从数据库执行" + sql2);*/
				String sql2 = "UPDATE test_bill  SET  test_status= '" + test_base_info.getTest_status() + "' , test_guide=? , req_remark=? WHERE id=?" ;
				logger.info("从数据库执行" + sql2);
				PreparedStatementSetter pss2 = new PreparedStatementSetter() {

					@Override
					public void setValues(PreparedStatement ps) throws SQLException {
						
						
						if(test_base_info.getTest_introduction()!=null){
							ps.setString(1, test_base_info.getTest_introduction());
						}else{
							ps.setString(1, "");
						}					
						
						if(test_base_info.getTest_remark()!=null){
							ps.setString(2, test_base_info.getTest_remark());
						}else{
							ps.setString(2, "");
						}
						
						ps.setInt(3, test_base_info.getTest_id());
					}
				};
				Integer get_r3 = jdbcTemplate.update(sql2,pss2);
				if (get_r3 > 0) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}

		} else {
			return false;
		}
		/*
		 * } catch (Exception e) { logger.info("Exception e :" +
		 * e.getMessage()); return false; } }
		 */
	}

	public Test_testing_info search_a_test_testing_info_by_testid(String test_id) {
		String sql = "SELECT * FROM test_testing_info WHERE test_id=" + test_id;
		logger.info("从数据库执行" + sql);
		List<Test_testing_info> l_u = jdbcTemplate.query(sql, new Test_testing_infoRowMapper());
		if (l_u.size() > 0) {
			return l_u.get(0);
		} else {
			return null;
		}
	}

	class Test_testing_infoRowMapper implements RowMapper<Test_testing_info> {
		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet,
		 * int)
		 */
		@Override
		public Test_testing_info mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_testing_info test_testing_info = new Test_testing_info();
			test_testing_info.setId(rs.getInt("ID"));
			test_testing_info.setTest_id(String.valueOf(rs.getInt("test_id")));
			test_testing_info.setTest_result(rs.getString("test_result"));
			test_testing_info.setTest_workload(rs.getFloat("test_workload"));

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String d_str = "";
			if (rs.getDate("test_start_date") != null) {
				d_str = sdf.format(rs.getDate("test_start_date"));
			}
			test_testing_info.setTest_start_date(d_str);

			d_str = "";
			if (rs.getDate("test_end_date") != null) {
				d_str = sdf.format(rs.getDate("test_end_date"));
			}
			test_testing_info.setTest_end_date(d_str);

			test_testing_info.setDeffect_critical_count(rs.getInt("deffect_critical_count"));
			test_testing_info.setDeffect_ordinary_count(rs.getInt("deffect_ordinary_count"));
			test_testing_info.setDeffect_other_count(rs.getInt("deffect_other_count"));

			test_testing_info.setTest_channel_is_Teller(rs.getString("test_channel_is_Teller"));
			test_testing_info.setTest_channel_is_Core(rs.getString("test_channel_is_Core"));
			test_testing_info.setTest_channel_is_ATM(rs.getString("test_channel_is_ATM"));
			test_testing_info
					.setTest_channel_is_self_service_terminals(rs.getString("test_channel_is_self_service_terminals"));
			test_testing_info.setTest_channel_is_Tel_bank(rs.getString("test_channel_is_Tel_bank"));
			test_testing_info.setTest_channel_is_Net_bank(rs.getString("test_channel_is_Net_bank"));
			test_testing_info.setTest_channel_is_Mobile_bank(rs.getString("test_channel_is_Mobile_bank"));
			test_testing_info.setTest_channel_is_Fill_form_machine(rs.getString("test_channel_is_Fill_form_machine"));
			test_testing_info.setTest_channel_is_Other(rs.getString("test_channel_is_Other"));
			test_testing_info.setTest_channel_other_info(rs.getString("test_channel_other_info"));

			test_testing_info.setTest_type_is_Query(rs.getString("test_type_is_Query"));
			test_testing_info.setTest_type_is_Maintain(rs.getString("test_type_is_Maintain"));
			test_testing_info.setTest_type_is_Query(rs.getString("test_type_is_Query"));
			test_testing_info.setTest_type_is_Finance(rs.getString("test_type_is_Finance"));
			test_testing_info.setTest_type_is_Other(rs.getString("test_type_is_Other"));
			test_testing_info.setTest_type_Other_info(rs.getString("test_type_Other_info"));

			test_testing_info.setRelation_funcation(rs.getString("relation_funcation"));

			test_testing_info.setTest_cover_is_certificate(rs.getString("test_cover_is_certificate"));
			test_testing_info.setTest_cover_is_certificate_Normal(rs.getString("test_cover_is_certificate_Normal"));
			test_testing_info
					.setTest_cover_is_certificate_Exception(rs.getString("test_cover_is_certificate_Exception"));
			test_testing_info.setTest_cover_is_account(rs.getString("test_cover_is_account"));
			test_testing_info.setTest_cover_is_account_Normal(rs.getString("test_cover_is_account_Normal"));
			test_testing_info.setTest_cover_is_account_Exception(rs.getString("test_cover_is_account_Exception"));
			test_testing_info.setTest_cover_is_balance(rs.getString("test_cover_is_balance"));
			test_testing_info.setTest_cover_is_balance_Normal(rs.getString("test_cover_is_balance_Normal"));
			test_testing_info.setTest_cover_is_balance_Exception(rs.getString("test_cover_is_balance_Exception"));
			test_testing_info.setTest_cover_is_password(rs.getString("test_cover_is_password"));
			test_testing_info.setTest_cover_is_password_Normal(rs.getString("test_cover_is_password_Normal"));
			test_testing_info.setTest_cover_is_password_Exception(rs.getString("test_cover_is_password_Exception"));
			test_testing_info.setTest_cover_is_accounting_entry(rs.getString("test_cover_is_accounting_entry"));
			test_testing_info.setTest_cover_is_limit_management(rs.getString("test_cover_is_limit_management"));
			test_testing_info.setTest_cover_is_business_process(rs.getString("test_cover_is_business_process"));
			test_testing_info.setTest_cover_is_operate_ui(rs.getString("test_cover_is_operate_ui"));
			test_testing_info.setTest_cover_is_batch_check(rs.getString("test_cover_is_batch_check"));
			test_testing_info.setTest_cover_is_MEMO_check(rs.getString("test_cover_is_MEMO_check"));
			test_testing_info.setTest_cover_is_Authorized_handle(rs.getString("test_cover_is_Authorized_handle"));
			test_testing_info.setTest_cover_is_data_aync(rs.getString("test_cover_is_data_aync"));
			test_testing_info.setTest_cover_is_answer_info(rs.getString("test_cover_is_answer_info"));
			test_testing_info.setTest_cover_is_account_checking(rs.getString("test_cover_is_account_checking"));
			test_testing_info.setTest_cover_is_bill_print(rs.getString("test_cover_is_bill_print"));
			test_testing_info.setTest_cover_is_Electronic_receipt(rs.getString("test_cover_is_Electronic_receipt"));
			test_testing_info.setTest_cover_is_opposite_info(rs.getString("test_cover_is_opposite_info"));
			test_testing_info.setTest_cover_is_summary_code(rs.getString("test_cover_is_summary_code"));
			test_testing_info.setTest_cover_is_report_form_info(rs.getString("test_cover_is_report_form_info"));
			test_testing_info.setTest_cover_is_SMS(rs.getString("test_cover_is_SMS"));
			test_testing_info.setTest_cover_is_hardware(rs.getString("test_cover_is_hardware"));
			test_testing_info.setTest_cover_is_load_test(rs.getString("test_cover_is_load_test"));
			test_testing_info.setTest_cover_is_timeout(rs.getString("test_cover_is_timeout"));
			test_testing_info.setTest_cover_is_exception(rs.getString("test_cover_is_exception"));
			test_testing_info.setTest_cover_is_other(rs.getString("test_cover_is_other"));
			test_testing_info.setTest_cover_other_info(rs.getString("test_cover_other_info"));

			test_testing_info.setOther_remark(rs.getString("other_remark"));

			d_str = "";
			if (rs.getDate("plan_online_date") != null) {
				d_str = sdf.format(rs.getDate("plan_online_date"));
			}
			test_testing_info.setPlan_online_date(d_str);

			test_testing_info.setPlan_online_step(rs.getString("plan_online_step"));
			test_testing_info.setContingency_plan(rs.getString("contingency_plan"));
			test_testing_info.setContingency_plan_remark(rs.getString("contingency_plan_remark"));
			test_testing_info.setOnline_trace_info(rs.getString("online_trace_info"));

			d_str = "";
			if (rs.getDate("online_trace_start_date") != null) {
				d_str = sdf.format(rs.getDate("online_trace_start_date"));
			}
			test_testing_info.setOnline_trace_start_date(d_str);

			d_str = "";
			if (rs.getDate("online_trace_end_date") != null) {
				d_str = sdf.format(rs.getDate("online_trace_end_date"));
			}
			test_testing_info.setOnline_trace_end_date(d_str);

			test_testing_info.setOnline_tracer(rs.getString("online_tracer"));

			test_testing_info.setAttention_is_inform_dept_offer(rs.getString("attention_is_inform_dept_offer"));
			test_testing_info.setAttention_is_business_check(rs.getString("attention_is_business_check"));
			test_testing_info.setAttention_is_bank_head_check(rs.getString("attention_is_bank_head_check"));
			test_testing_info.setAttention_is_bank_head_check_yes(rs.getString("attention_is_bank_head_check_yes"));
			test_testing_info.setAttention_is_bank_head_check_no(rs.getString("attention_is_bank_head_check_no"));
			test_testing_info.setAttention_is_other(rs.getString("attention_is_other"));
			test_testing_info.setAttention_other_info(rs.getString("attention_other_info"));

			return test_testing_info;
		}

	}

	public boolean save_test_testing_info(Test_testing_info test_testing_info) {
		String test_id = String.valueOf(test_testing_info.getTest_id());
		Test_testing_info t = search_a_test_testing_info_by_testid(test_id);
		if (t == null) {
			new_a_test_testing_info(test_id);
			/*
			 * if(test_testing_info_id){ Test_testing_info
			 * t2=search_a_test_testing_info_by_testid(test_id);
			 * test_testing_info.setId(t2.getId()); }else{ return false; }
			 */
		}

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String sql_set_ = "";
		String Test_start_date = "";
		if (test_testing_info.getTest_start_date() != null) {
			String tmp = sdf.format(test_testing_info.getTest_start_date());
			Test_start_date = "test_start_date=Date('" + tmp + "'),";
		}

		String Test_end_date = "";
		if (test_testing_info.getTest_end_date() != null) {
			String tmp = sdf.format(test_testing_info.getTest_end_date());
			Test_end_date = "test_end_date=Date('" + tmp + "'),";
		}

		String deffect_critical_count = "";
		if (test_testing_info.getDeffect_critical_count() != null) {
			deffect_critical_count = "deffect_critical_count=" + test_testing_info.getDeffect_critical_count() + ",";
		}

		String deffect_ordinary_count = "";
		if (test_testing_info.getDeffect_ordinary_count() != null) {
			deffect_ordinary_count = "deffect_ordinary_count=" + test_testing_info.getDeffect_ordinary_count() + ",";
		}

		String deffect_other_count = "";
		if (test_testing_info.getDeffect_other_count() != null) {
			deffect_other_count = "deffect_other_count=" + test_testing_info.getDeffect_other_count() + ",";
		}

		String plan_online_date = "";
		if (test_testing_info.getPlan_online_date() != null) {
			String tmp = sdf.format(test_testing_info.getPlan_online_date());
			plan_online_date = "plan_online_date=Date('" + tmp + "'),";
		}

		String online_trace_start_date = "";
		if (test_testing_info.getOnline_trace_start_date() != null) {
			String tmp = sdf.format(test_testing_info.getOnline_trace_start_date());
			online_trace_start_date = "online_trace_start_date=Date('" + tmp + "'),";
		}
		String online_trace_end_date = "";
		if (test_testing_info.getOnline_trace_end_date() != null) {
			String tmp = sdf.format(test_testing_info.getOnline_trace_end_date());
			online_trace_end_date = "online_trace_end_date=Date('" + tmp + "'),";
		}

		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String modify_time = sdf2.format(new java.util.Date());

		String sql = "" + "UPDATE test_testing_info " + " SET " + "test_id =" + test_testing_info.getTest_id() + ","
				+ "test_result='" + test_testing_info.getTest_result() + "'," + "test_workload="
				+ test_testing_info.getTest_workload() + "," + Test_start_date + Test_end_date + deffect_critical_count
				+ deffect_ordinary_count + deffect_other_count + "test_channel_is_Teller='"
				+ test_testing_info.getTest_channel_is_Teller() + "'," + "test_channel_is_Core='"
				+ test_testing_info.getTest_channel_is_Core() + "'," + "test_channel_is_ATM='"
				+ test_testing_info.getTest_channel_is_ATM() + "'," + "test_channel_is_self_service_terminals='"
				+ test_testing_info.getTest_channel_is_self_service_terminals() + "'," + "test_channel_is_Tel_bank='"
				+ test_testing_info.getTest_channel_is_Tel_bank() + "'," + "test_channel_is_Net_bank='"
				+ test_testing_info.getTest_channel_is_Net_bank() + "'," + "test_channel_is_Mobile_bank='"
				+ test_testing_info.getTest_channel_is_Mobile_bank() + "'," + "test_channel_is_Fill_form_machine='"
				+ test_testing_info.getTest_channel_is_Fill_form_machine() + "'," + "test_channel_is_Other='"
				+ test_testing_info.getTest_channel_is_Other() + "'," + "test_channel_other_info='"
				+ test_testing_info.getTest_channel_other_info() + "'," + "test_type_is_Query='"
				+ test_testing_info.getTest_type_is_Query() + "'," + "test_type_is_Maintain='"
				+ test_testing_info.getTest_type_is_Maintain() + "'," + "test_type_is_Finance='"
				+ test_testing_info.getTest_type_is_Finance() + "'," + "test_type_is_Other='"
				+ test_testing_info.getTest_type_is_Other() + "'," + "test_type_Other_info='"
				+ test_testing_info.getTest_type_Other_info() + "'," + "relation_funcation=?," + "test_cover_is_certificate='"
				+ test_testing_info.getTest_cover_is_certificate() + "'," + "test_cover_is_certificate_Normal='"
				+ test_testing_info.getTest_cover_is_certificate_Normal() + "',"
				+ "test_cover_is_certificate_Exception='" + test_testing_info.getTest_cover_is_certificate_Exception()
				+ "'," + "test_cover_is_account='" + test_testing_info.getTest_cover_is_account() + "',"
				+ "test_cover_is_account_Normal='" + test_testing_info.getTest_cover_is_account_Normal() + "',"
				+ "test_cover_is_account_Exception='" + test_testing_info.getTest_cover_is_account_Exception() + "',"
				+ "test_cover_is_balance='" + test_testing_info.getTest_cover_is_balance() + "',"
				+ "test_cover_is_balance_Normal='" + test_testing_info.getTest_cover_is_balance_Normal() + "',"
				+ "test_cover_is_balance_Exception='" + test_testing_info.getTest_cover_is_balance_Exception() + "',"
				+ "test_cover_is_password='" + test_testing_info.getTest_cover_is_password() + "',"
				+ "test_cover_is_password_Normal='" + test_testing_info.getTest_cover_is_password_Normal() + "',"
				+ "test_cover_is_password_Exception='" + test_testing_info.getTest_cover_is_password_Exception() + "',"
				+ "test_cover_is_accounting_entry='" + test_testing_info.getTest_cover_is_accounting_entry() + "',"
				+ "test_cover_is_limit_management='" + test_testing_info.getTest_cover_is_limit_management() + "',"
				+ "test_cover_is_business_process='" + test_testing_info.getTest_cover_is_business_process() + "',"
				+ "test_cover_is_operate_ui='" + test_testing_info.getTest_cover_is_operate_ui() + "',"
				+ "test_cover_is_batch_check='" + test_testing_info.getTest_cover_is_batch_check() + "',"
				+ "test_cover_is_MEMO_check='" + test_testing_info.getTest_cover_is_MEMO_check() + "',"
				+ "test_cover_is_Authorized_handle='" + test_testing_info.getTest_cover_is_Authorized_handle() + "',"
				+ "test_cover_is_data_aync='" + test_testing_info.getTest_cover_is_data_aync() + "',"
				+ "test_cover_is_answer_info='" + test_testing_info.getTest_cover_is_answer_info() + "',"
				+ "test_cover_is_account_checking='" + test_testing_info.getTest_cover_is_account_checking() + "',"
				+ "test_cover_is_bill_print='" + test_testing_info.getTest_cover_is_bill_print() + "',"
				+ "test_cover_is_Electronic_receipt='" + test_testing_info.getTest_cover_is_Electronic_receipt() + "',"
				+ "test_cover_is_opposite_info='" + test_testing_info.getTest_cover_is_opposite_info() + "',"
				+ "test_cover_is_summary_code='" + test_testing_info.getTest_cover_is_summary_code() + "',"
				+ "test_cover_is_report_form_info='" + test_testing_info.getTest_cover_is_report_form_info() + "',"
				+ "test_cover_is_SMS='" + test_testing_info.getTest_cover_is_SMS() + "'," + "test_cover_is_hardware='"
				+ test_testing_info.getTest_cover_is_hardware() + "'," + "test_cover_is_load_test='"
				+ test_testing_info.getTest_cover_is_load_test() + "'," + "test_cover_is_timeout='"
				+ test_testing_info.getTest_cover_is_timeout() + "'," + "test_cover_is_exception='"
				+ test_testing_info.getTest_cover_is_exception() + "'," + "test_cover_is_other='"
				+ test_testing_info.getTest_cover_is_other() + "'," + "test_cover_other_info='"
				+ test_testing_info.getTest_cover_other_info() + "'," + "other_remark=?," + plan_online_date + "plan_online_step='"
				+ test_testing_info.getPlan_online_step() + "'," + "contingency_plan='"
				+ test_testing_info.getContingency_plan() + "'," + "contingency_plan_remark='"
				+ test_testing_info.getContingency_plan_remark() + "'," + "online_trace_info='"
				+ test_testing_info.getOnline_trace_info() + "'," + online_trace_start_date + online_trace_end_date
				+ "online_tracer='" + test_testing_info.getOnline_tracer() + "'," + "attention_is_inform_dept_offer='"
				+ test_testing_info.getAttention_is_inform_dept_offer() + "'," + "attention_is_business_check='"
				+ test_testing_info.getAttention_is_business_check() + "'," + "attention_is_bank_head_check='"
				+ test_testing_info.getAttention_is_bank_head_check() + "'," + "attention_is_bank_head_check_yes='"
				+ test_testing_info.getAttention_is_bank_head_check_yes() + "'," + "attention_is_bank_head_check_no='"
				+ test_testing_info.getAttention_is_bank_head_check_no() + "'," + "attention_is_other='"
				+ test_testing_info.getAttention_is_other() + "'," + "attention_other_info='"
				+ test_testing_info.getAttention_other_info() + "',"

				+ "modify_time=Date('" + modify_time + "')" + "WHERE test_id = " + test_testing_info.getTest_id();
		
		PreparedStatementSetter pss = new PreparedStatementSetter() {

			@Override
			public void setValues(PreparedStatement ps) throws SQLException {
				ps.setString(1, test_testing_info.getRelation_funcation());
				ps.setString(2, test_testing_info.getOther_remark());						
			}
		};
		Integer get_r = jdbcTemplate.update(sql,pss);
		if (get_r > 0) {
			return true;
		} else {
			return false;
		}

	}

	private boolean new_a_test_testing_info(String test_id) {
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String modify_time = sdf2.format(new java.util.Date());

		String sql = "INSERT INTO test_testing_info" + "(test_id,create_time)values(" + test_id + ",Date('"
				+ modify_time + "'));";

		Integer get_r = jdbcTemplate.update(sql);
		if (get_r == 1) {

			return true;

		} else {
			return false;
		}

	}

	public boolean add_test_team_info_log(Map<String, Object> map) {
		String sql2 = "INSERT INTO test_team_info"
				+ "(user_name,operate,remark,role,test_id,operate_time)values(?,?,?,?,?,?);";
		logger.info("从数据库执行" + sql2);
		try {
			PreparedStatementSetter pss = new PreparedStatementSetter() {

				@Override
				public void setValues(PreparedStatement ps) throws SQLException {
					ps.setString(1, (String) map.get("user_name"));
					ps.setString(2, (String) map.get("operate"));
					ps.setString(3, (String) map.get("remark"));
					ps.setString(4, (String) map.get("role"));
					ps.setInt(5, Integer.parseInt((String) map.get("test_id")));
					Date date = new java.sql.Date(new java.util.Date().getTime());
					Timestamp timeStamp = new Timestamp(date.getTime());
					// ps.setDate(6, new java.sql.Date(new
					// java.util.Date().getTime()));
					ps.setTimestamp(6, timeStamp);
				}
			};
			Integer get_r = jdbcTemplate.update(sql2, pss);
			if (get_r == 1) {
				return true;
			} else {
				return false;
			}

		} catch (Exception e) {
			logger.info("Exception e :" + e.getMessage());
			return false;
		}
	}

	public boolean update_test_team_info(Map<String, Object> m) {
		String sql = "UPDATE test_base_info  SET  test_head='" + (String) m.get("test_head") + "', test_executor ='"
				+ (String) m.get("test_executor") + "' " + "WHERE test_id =" + (String) m.get("test_id");
		logger.info("从数据库执行" + sql);
		Integer get_r = jdbcTemplate.update(sql);
		if (get_r > 0) {
			return true;
		} else {
			return false;
		}
	}

	public List<Test_team_info_log> search_test_team_info_log(String test_id) {
		String sql = "SELECT id,user_name,operate,remark,role,test_id,operate_time FROM test_team_info WHERE test_id="
				+ test_id + " ORDER BY operate_time DESC";
		logger.info("从数据库执行" + sql);
		List<Test_team_info_log> l_q = jdbcTemplate.query(sql, new Test_team_info_log_RowMapper());

		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}
	}

	class Test_team_info_log_RowMapper implements RowMapper<Test_team_info_log> {
		@Override
		public Test_team_info_log mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_team_info_log q = new Test_team_info_log();
			q.setId(rs.getInt("ID"));
			q.setOperate(rs.getString("operate"));
			q.setOperate_time(rs.getTimestamp("operate_time"));
			q.setRemark(rs.getString("remark"));
			q.setTest_id(rs.getInt("test_id"));
			q.setRole(rs.getString("role"));
			q.setUser_name(rs.getString("user_name"));
			return q;
		}

	}

	public List<Test_workload_info> search_test_workload_info(String test_id) {
		String sql = "SELECT * " + "FROM test_workload_info WHERE test_id=" + test_id;
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}
	}

	class Test_workload_info_RowMapper implements RowMapper<Test_workload_info> {
		@Override
		public Test_workload_info mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_workload_info q = new Test_workload_info();
			q.setId(rs.getInt("ID"));
			q.setTest_id(rs.getInt("test_id"));
			q.setRole(rs.getString("role"));
			q.setUser_name(rs.getString("user_name"));
			q.setPlan_complete_date(rs.getDate("plan_complete_date"));
			q.setActual_complete_date(rs.getDate("actual_complete_date"));
			q.setPlan_workload(String.valueOf(rs.getFloat("plan_workload")));
			q.setActual_workload(String.valueOf(rs.getFloat("actual_workload")));
			q.setModify_datetime(rs.getDate("modify_datetime"));
			q.setOnline_testcase_count(rs.getInt("online_testcase_count"));
			q.setBatch_testcase_count(rs.getInt("batch_testcase_count"));
			return q;
		}

	}

	public List<String> search_test_workload_info_by_role(String test_id, String role) {
		String sql = "SELECT * " + "FROM test_workload_info WHERE test_id=" + test_id + " AND role ='" + role + "'";
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			List<String> r_list = new ArrayList<String>();
			for (int i = 0; i < l_q.size(); i++) {
				String tmp = l_q.get(i).getUser_name();
				r_list.add(tmp);
			}
			return r_list;
		} else {
			return null;
		}
	}

	public Test_workload_info search_a_test_workload_info(String test_id, String user_name, String role) {
		String sql = "SELECT * " + "FROM test_workload_info WHERE test_id=" + test_id + " AND user_name='" + user_name
				+ "' AND role='" + role + "'";
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			return l_q.get(0);
		} else {
			return null;
		}
	}

	public boolean test_workload_info_save(Map<String, Object> map) {
		// 判断是否已存在
		int test_id = (int) map.get("test_id");
		String g_user_name = (String) map.get("user_name");
		String g_role = (String) map.get("role");
		String g_plan_complete_date = (String) map.get("plan_complete_date");
		String g_actual_complete_date = (String) map.get("actual_complete_date");
		String g_plan_workload = (String) map.get("plan_workload");
		String g_actual_workload = (String) map.get("actual_workload");
		String g_online_testcase_count=(String) map.get("online_testcase_count");
		String g_batch_testcase_count=(String) map.get("batch_testcase_count");
		
		Test_workload_info l_q = search_a_test_workload_info(String.valueOf(test_id), g_user_name, g_role);
		if (l_q == null) {
			// 插入
			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String modify_time = sdf2.format(new java.util.Date());
			String sql = "INSERT INTO test_workload_info" + "(test_id,user_name,role,create_time)values(" + test_id + ",'"+g_user_name+"','"+g_role+"', Date('"
					+ modify_time + "'));";

			Integer get_r = jdbcTemplate.update(sql);
			if (get_r == 1) {
			} else {
				return false;
			}
		}
		// update
		try {
			String set_sql = "";
			if (!g_plan_complete_date.equals("")) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				java.util.Date d_tmp;

				d_tmp = sdf.parse(g_plan_complete_date);

				Date sqlDate = null;
				sqlDate = new Date(d_tmp.getTime());

				set_sql = set_sql + " plan_complete_date = Date('" + sqlDate + "')";
			}
			if (!g_actual_complete_date.equals("")) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				java.util.Date d_tmp;
				d_tmp = sdf.parse(g_actual_complete_date);
				Date sqlDate = null;
				sqlDate = new Date(d_tmp.getTime());
				if (set_sql.length() > 3) {
					set_sql = set_sql + ", actual_complete_date = Date('" + sqlDate + "')";
				} else {
					set_sql = set_sql + " actual_complete_date =Date('" + sqlDate + "')";
				}
			}
			if (!g_plan_workload.equals("")) {
				if (set_sql.length() > 3) {
					set_sql = set_sql + ", plan_workload =" + g_plan_workload;
				} else {
					set_sql = set_sql + " plan_workload =" + g_plan_workload;
				}
			}
			if (!g_actual_workload.equals("")) {

				if (set_sql.length() > 3) {
					set_sql = set_sql + ", actual_workload =" + g_actual_workload;
				} else {
					set_sql = set_sql + " actual_workload =" + g_actual_workload;
				}
			}

			if (!g_online_testcase_count.equals("")) {

				if (set_sql.length() > 3) {
					set_sql = set_sql + ", online_testcase_count =" + g_online_testcase_count;
				} else {
					set_sql = set_sql + " online_testcase_count =" + g_online_testcase_count;
				}
			}
			
			if (!g_batch_testcase_count.equals("")) {

				if (set_sql.length() > 3) {
					set_sql = set_sql + ", batch_testcase_count =" + g_batch_testcase_count;
				} else {
					set_sql = set_sql + " batch_testcase_count =" + g_batch_testcase_count;
				}
			}
			
			if (set_sql.length() > 3) {
				// 存在更新
				String sql2 = "UPDATE test_workload_info  SET " + set_sql + " WHERE test_id =" + test_id
						+ " AND user_name = '" + g_user_name + "' AND role ='" + g_role + "'";
				logger.info("从数据库执行" + sql2);
				Integer get_r = jdbcTemplate.update(sql2);
				if (get_r > 0) {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	public List<Test_work_log> search_test_work_log(String test_id) {
		String sql = "SELECT * FROM test_workload_log WHERE test_id=" + test_id +" order by work_date desc" ;
		logger.info("从数据库执行" + sql);
		List<Test_work_log> l_q = jdbcTemplate.query(sql, new Test_work_logRowMapper());

		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}
	}
	
	
	
	class Test_work_logRowMapper implements RowMapper<Test_work_log> {
		@Override
		public Test_work_log mapRow(ResultSet rs, int rowNum) throws SQLException {
			Test_work_log q = new Test_work_log();
			q.setId(rs.getInt("ID"));
			q.setUser_name(rs.getString("user_name"));
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date d=rs.getDate("work_date");
			q.setWork_date(sdf.format(d));
			q.setWork_log(rs.getString("work_log"));
			q.setTest_id(rs.getInt("test_id"));

			return q;
		}

	}

	public boolean save_test_work_log(Test_work_log test_work_log) {
		// 判断req_id对应用户和日期是否存在
				boolean is_update=false;
				int test_id=test_work_log.getTest_id();
				String user=test_work_log.getUser_name();
				java.util.Date work_date=test_work_log.getWork_date();
				Date sqlDate = null;
				if(work_date!=null){
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");			
					sqlDate = new Date(work_date.getTime());
				}
				String sql = "SELECT * FROM test_workload_log WHERE test_id=" + test_id +" AND user_name='"+user+"' AND work_date= Date('" + sqlDate+"')" ;
				logger.info("从数据库执行" + sql);
				List<Test_work_log> l_q = jdbcTemplate.query(sql, new Test_work_logRowMapper());

				if (l_q.size() > 0) {
					is_update=true;
				} else {
					is_update=false;
				}
				
				if(is_update){
					//存在就更新
					Test_work_log log=l_q.get(0);
					int get_id=log.getId();
					//String sql2 = "UPDATE test_workload_log  SET work_log ='"+test_work_log.getWork_log()+"' WHERE id =" + get_id;
					String sql2 = "UPDATE test_workload_log  SET work_log =? WHERE id =?" ;
					PreparedStatementSetter pss = new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps) throws SQLException {
							ps.setString(1, test_work_log.getWork_log());
							ps.setInt(2, get_id);						
						}
					};
					
					logger.info("从数据库执行" + sql2);
					Integer get_r = jdbcTemplate.update(sql2,pss);
					if (get_r > 0) {
						return true;
					} else {
						return false;
					}				
				}else{
					//不存在就插入			
					String sql3 = "INSERT INTO test_workload_log (test_id,user_name,work_date,work_log,creator_datetime)VALUES(?,?,?,?,?); ";
					try {
						PreparedStatementSetter pss = new PreparedStatementSetter() {

							@Override
							public void setValues(PreparedStatement ps) throws SQLException {
								ps.setInt(1, test_id);
								ps.setString(2, user);
								Date sqlDate_work_date = null;
								
								SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
								java.util.Date d_tmp;
								sqlDate_work_date = new Date(work_date.getTime());
								ps.setDate(3, sqlDate_work_date);
								ps.setString(4, test_work_log.getWork_log());
								Date date = new java.sql.Date(new java.util.Date().getTime());
								Timestamp timeStamp = new Timestamp(date.getTime());						
								ps.setTimestamp(5, timeStamp);
							}
						};
						Integer get_r = jdbcTemplate.update(sql3, pss);
						if (get_r == 1) {
							return true;
						} else {
							return false;
						}

					} catch (Exception e) {
						logger.info("Exception e :" + e.getMessage());
						return false;
					}
				}
	}

	public void delet_a_work_log(String id) {
		jdbcTemplate .update( "delete from test_workload_log where id="+id);
		
	}

	public boolean test_reject_save(String id, String other_reason, String reason_select) {
		if(other_reason==null){
			other_reason="";
		}
		String sql = "UPDATE test_bill  SET other_reason ='" + other_reason + "', select_reason ='" + reason_select + "',  test_status='已退回' WHERE ID =" + id;
		logger.info("从数据库执行" + sql);
		Integer get_r = jdbcTemplate.update(sql);
		if (get_r > 0) {
			return true;
		} else {
			return false;
		}
	}

	public double search_a_test_act_workload(String test_id) {
		double return_value=0.0;
		String sql = "SELECT * FROM test_workload_info WHERE test_id=" + test_id;
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			for (Test_workload_info req_workload_info : l_q) {
				String tmp=req_workload_info.getActual_workload();
				if(tmp.equals("")||tmp!=null){
					return_value=return_value+Double.parseDouble(tmp);
				}
			}
			return return_value;
		} else {
			return 0;
		}
	}

	public List<Test_work_log> search_req_work_log_by_name(String test_id, String user_name) {
		String sql = "SELECT * FROM test_workload_log WHERE test_id=" + test_id +" AND user_name ='"+user_name+"' order by work_date desc" ;
		logger.info("从数据库执行" + sql);
		List<Test_work_log> l_q = jdbcTemplate.query(sql, new Test_work_logRowMapper());

		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}
	}

	public List<Test_bill> search_all_test() {
		String sql = "SELECT * FROM test_bill ";
		logger.info("从数据库执行" + sql);
		List<Test_bill> l_u = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_u.size() > 0) {
			return l_u;
		} else {
			return null;
		}
	}

	public List<Test_bill> query_test(HttpServletRequest request) {
		
//		send_test_date_start:
		String send_test_date_start=(String) request.getParameter("send_test_date_start");
//			send_test_date_end:
		String send_test_date_end=(String) request.getParameter("send_test_date_end");
//			assign_test_date_start:
		String assign_test_date_start=(String) request.getParameter("assign_test_date_start");
//			assign_test_date_end:
		String assign_test_date_end=(String) request.getParameter("assign_test_date_end");
//			required_completion_date_start:
		String required_completion_date_start=(String) request.getParameter("required_completion_date_start");
//			required_completion_date_end:
		String required_completion_date_end=(String) request.getParameter("required_completion_date_end");
//			plan_completion_date_start:
		String plan_completion_date_start=(String) request.getParameter("plan_completion_date_start");
//			plan_completion_date_end:
		String plan_completion_date_end=(String) request.getParameter("plan_completion_date_end");
//			act_completion_date_start:
		String act_completion_date_start=(String) request.getParameter("act_completion_date_start");
		//act_completion_date_end:
			String act_completion_date_end=(String) request.getParameter("act_completion_date_end");
//			test_expire:0
		String test_expire=(String) request.getParameter("test_expire");
//			req_bill_no:
		String req_bill_no=(String) request.getParameter("req_bill_no");
//			req_titile:
		String req_titile=(String) request.getParameter("req_titile");
//			test_status:
		String test_status=(String) request.getParameter("test_status");
//			test_difficult:
		String test_difficult=(String) request.getParameter("test_difficult");
//			deffect_no:
		String deffect_no=(String) request.getParameter("deffect_no");
//			user_name:
		String user_name=(String) request.getParameter("user_name");
//			role:
		String role=(String) request.getParameter("role");
//			test_workload_date_start:
		String test_workload_date_start=(String) request.getParameter("test_workload_date_start");
//			test_workload_date_end:
		String test_workload_date_end=(String) request.getParameter("test_workload_date_end");
//			Name
//			query_test_form_send
		String sql = "SELECT test_bill.* FROM test_bill LEFT JOIN test_base_info  ON test_bill.id= test_base_info.test_id WHERE test_bill.test_status is not null ";
		if (!send_test_date_start.equals("")) {
			sql = sql + " AND test_bill.create_date > date('"+send_test_date_start+ "') ";
			if(!send_test_date_end.equals("")){
				sql = sql+"  AND  test_bill.create_date <date('" + send_test_date_end + "') ";
			}				
		}
		if (!assign_test_date_start.equals("")) {
			sql = sql + " AND test_base_info.create_time > date('"+assign_test_date_start+ "') ";
			if(!assign_test_date_end.equals("")){
				sql = sql+"  AND  test_base_info.create_time <date('" + assign_test_date_end + "') ";
			}		
		}
		if (!required_completion_date_start.equals("")) {
			sql = sql + " AND test_bill.test_complete_date >  date('" + required_completion_date_start + "') ";
			if(!required_completion_date_end.equals("")){
				sql = sql+"  AND  test_bill.test_complete_date < date('" + required_completion_date_end + "') ";
			}	
		}		
		
		if (!plan_completion_date_start.equals("")) {
			sql = sql + " AND test_base_info.test_plan_date >  date('" + plan_completion_date_start + "') ";
			if(!plan_completion_date_end.equals("")){
				sql = sql+"  AND  test_base_info.test_plan_date < date('" + plan_completion_date_end + "') ";
			}	
		}
		
		
		if (!act_completion_date_start.equals("")) {
			sql = sql + " AND test_base_info.actual_finish_date >  date('" + act_completion_date_start + "') ";
			if(!act_completion_date_end.equals("")){
				sql = sql+"  AND  test_base_info.actual_finish_date < date('" + act_completion_date_end + "') ";
			}	
		}
		
		if (test_expire.equals("1")) {
			sql = sql + " AND test_bill.test_complete_date < test_base_info.actual_finish_date";
		}
		
		if (!req_bill_no.equals("")) {
			sql = sql + " AND test_bill.id in (select test_bill.id from test_bill,req_bill where test_bill.req_id=req_bill.ID and req_bill.req_bill_no like '%"+req_bill_no+"%') ";
		}
		
		if (!req_titile.equals("")) {
			sql = sql + " AND test_bill.id in (select test_bill.id from test_bill,req_bill where test_bill.req_id=req_bill.ID AND req_bill.req_title like '%"+req_titile+"%') ";
		}
						
		if (!test_status.equals("")) {
			sql = sql + " AND test_bill.test_status like '%"+test_status+"%' ";
		}
		
		if (!test_difficult.equals("")) {
			sql = sql + " AND test_base_info.test_difficult like '%"+test_difficult+"%' ";
		}
		if (!deffect_no.equals("")) {
			sql = sql + " AND test_bill.id in (select test_bill.id from test_bill,req_bill where test_bill.req_id=req_bill.ID AND req_bill.deffect_no like '%"+deffect_no+"%' )";
		}
		
	
		if (!user_name.equals("")) {
			if(!role.equals("")){
				String role1="测试负责人";
				String role2="测试执行人";
				//String role3="需求监理人";
				if(role.equals(role1)){
					sql = sql + " AND test_base_info.test_head like '%"+user_name+"%' ";
				}
				if(role.equals(role2)){
					sql = sql + " AND test_base_info.test_executor like '%"+user_name+"%' ";
				}
				/*if(req_role.equals(role3)){
					sql = sql + " AND req_base_info.req_supervisor like '%"+title_key+"%' ";
				}*/
				
			}else{
				sql = sql + " AND (test_base_info.test_head like '%"+user_name+"%' OR "
						+ "test_base_info.test_executor like '%"+user_name+"%' ) ";
			}
			
		}
		
	
	
	/*	String req_workload_date_start=(String) request.getParameter("req_workload_date_start");
		String req_workload_date_end=(String) request.getParameter("req_workload_date_end");*/
		
		
		sql=sql+" ORDER BY test_bill.id DESC ";
		
		logger.info("从数据库执行" + sql);
		List<Test_bill> l_q = jdbcTemplate.query(sql, new Test_billRowMapper());
		if (l_q.size() > 0) {
			return l_q;
		} else {
			return null;
		}
		
	}

	public double get_a_test_all_of_planworkload(Integer id) {
		double r=0.0;
		String sql = "SELECT * "
				+ "FROM test_workload_info WHERE test_id=" + id ;
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			for (int i = 0; i < l_q.size(); i++) {
				Test_workload_info e=l_q.get(i);
				
				if ( e.getPlan_workload()!=null){
					if(!e.getPlan_workload().equals("")){
						double g_workload=Double.parseDouble( e.getPlan_workload());
						r=r+g_workload;
					}
					
				}
			}
			return r;
		} else {
			return r;
		}
	}

	public double get_a_test_all_of_actualworkload(Integer id) {
		double r=0.0;
		String sql = "SELECT * "
				+ "FROM test_workload_info WHERE test_id=" + id ;
		logger.info("从数据库执行" + sql);
		List<Test_workload_info> l_q = jdbcTemplate.query(sql, new Test_workload_info_RowMapper());

		if (l_q.size() > 0) {
			for (int i = 0; i < l_q.size(); i++) {
				Test_workload_info e=l_q.get(i);
				
				if ( e.getActual_workload()!=null){
					if(!e.getActual_workload().equals("")){
					double g_workload=Double.parseDouble( e.getActual_workload());
					r=r+g_workload;
					}
				}
			}
			return r;
		} else {
			return r;
		}
	}

	public Test_work_log get_a_test_worklog_by_log_id(String log_id) {
		String sql = "SELECT * FROM test_workload_log WHERE id=" + log_id  ;
		logger.info("从数据库执行" + sql);
		List<Test_work_log> l_q = jdbcTemplate.query(sql, new Test_work_logRowMapper());

		if (l_q!=null) {
			return l_q.get(0);
		} else {
			return null;
		}
	}
	public java.util.Date search_node_value_date_by_test_id_and_value(String test_id, String node_value) {
		String value1="1领取需求";
		String value2="2提交需求";
		String value3="3开始开发";
		String value4="4系统测试";
		String value5="5应用测试";
		String value6="6完成测试";
		String value7="7完成上线";
		String value8="8结束跟踪";
		
		String sql_select ="";
		String feild_str="";
			if(node_value.equals(value1)){
				sql_select = "select receive_req ";
				feild_str="receive_req";
			}
			if(node_value.equals(value2)){
				sql_select = "select submit_req ";
				feild_str="submit_req";
			}
			if(node_value.equals(value3)){
				sql_select = "select start_dev ";
				feild_str="start_dev";
			}
			if(node_value.equals(value4)){
				sql_select = "select system_test ";
				feild_str="system_test";
			}
			if(node_value.equals(value5)){
				sql_select = "select application_testing ";
				feild_str="application_testing";
			}
			if(node_value.equals(value6)){
				sql_select = "select test_finish ";
				feild_str="test_finish";
			}
			if(node_value.equals(value7)){
				sql_select = "select online_finish ";
				feild_str="online_finish";
			}
			if(node_value.equals(value8)){
				sql_select = "select trace_finish ";
				feild_str="trace_finish";
			}
		
		List rows = jdbcTemplate.queryForList(sql_select+" FROM test_node_info where test_id="+test_id);
		if(rows.size()>0){
			Map map=(Map) rows.get(0);
			Timestamp ts = (Timestamp) map.get(feild_str);   
			java.util.Date date = new java.util.Date();   
	        try {   
	            date = ts;   
	            System.out.println(date);   
	        } catch (Exception e) {   
	            e.printStackTrace();   
	        }    
			
			return date;
		}else{
			return null;
		}

}

	private boolean update_test_project_node_time(Integer test_id, String node_value,java.util.Date new_date) {
		String value1="1领取需求";
		String value2="2提交需求";
		String value3="3开始开发";
		String value4="4系统测试";
		String value5="5应用测试";
		String value6="6完成测试";
		String value7="7完成上线";
		String value8="8结束跟踪";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String d=sdf.format(new_date);
		int is_insert=0;
		List rows = jdbcTemplate.queryForList("SELECT id FROM test_node_info where test_id="+test_id);
		if(rows.size()>0){
			is_insert=0;
		}else{
			is_insert=1;
		}
		if(is_insert==1){
			String sql ="";
			if(node_value.equals(value1)){
				sql = "INSERT INTO test_node_info(test_id,receive_req) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value2)){
				sql = "INSERT INTO test_node_info(test_id,submit_req) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value3)){
				sql = "INSERT INTO test_node_info(test_id,start_dev) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value4)){
				sql = "INSERT INTO test_node_info(test_id,system_test) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value5)){
				sql = "INSERT INTO test_node_info(test_id,application_testing) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value6)){
				sql = "INSERT INTO test_node_info(test_id,test_finish) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value7)){
				sql = "INSERT INTO test_node_info(test_id,online_finish) VALUES (" + test_id+",date('"+d+"'))";
			}
			if(node_value.equals(value8)){
				sql = "INSERT INTO test_node_info(test_id,trace_finish) VALUES (" + test_id+",date('"+d+"'))";
			}
			logger.info("sql :" + sql);
			int r = jdbcTemplate.update(sql);
			if(r==1){
				return true;
			}else{
				return false;
			}
		}else{
			String sql ="";
			if(node_value.equals(value1)){
				sql = "UPDATE test_node_info SET receive_req=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value2)){
				sql = "UPDATE test_node_info SET submit_req=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value3)){
				sql = "UPDATE test_node_info SET start_dev=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value4)){
				sql = "UPDATE test_node_info SET system_test=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value5)){
				sql = "UPDATE test_node_info SET application_testing=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value6)){
				sql = "UPDATE test_node_info SET test_finish=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value7)){
				sql = "UPDATE test_node_info SET online_finish=date('"+d+"') WHERE test_id=" + test_id;
			}
			if(node_value.equals(value8)){
				sql = "UPDATE test_node_info SET trace_finish=date('"+d+"') WHERE test_id=" + test_id;
			}
			
			logger.info("sql :" + sql);
			int r = jdbcTemplate.update(sql);
			if(r==1){
				return true;
			}else{
				return false;
			}
		}		
	}
	
	public int count_end_trace_project() {
		
			String sql = "SELECT * FROM testmgnt.test_base_info WHERE node_value='8结束跟踪'";
			logger.info("从数据库执行" + sql);
			List<Test_base_info> l_q = jdbcTemplate.query(sql, new Test_base_infoRowMapper());

			if (l_q!=null) {
				return l_q.size();
			} else {
				return 0;
			}	
			
		}
	
	
}
